<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateProductBasesTable extends Migration
{
    /**
     * SPU：商品基础信息表
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('product_bases')) {
            Schema::create('product_bases', function (Blueprint $table) {
                $table->id();
                $table->string('title')->comment('商品标题');
                $table->string('subtitle')->nullable()->comment('商品副标题');
                $table->string('product_no')->nullable()->comment('商品编码');
                $table->string('tag_ids')->nullable()->comment('商品标签ID,多标签用逗号分割');
                $table->integer('uid')->comment('用户ID, 代指商品发布者');
                $table->integer('brand_id')->comment('品牌 ID');
                $table->integer('category_id')->comment('品类 ID');
                $table->integer('cover_img')->nullable()->comment('商品封面图');
                $table->string('gallery_img')->nullable()->comment('商品陈列图');
                $table->string('unit', 24)->default('千克')->comment('商品单位:吨/千克/磅/克/升/毫升');
                $table->bigInteger('price')->default(0)->comment('单价,单位:分');
                $table->bigInteger('weight')->default(0)->comment('单位重量,单位:克/毫升');
                $table->string('remark')->nullable()->comment('备注');
                $table->enum('status', ['normal', 'nosale'])->default('normal')->comment('商品状态: 上架 / 下架');
                $table->softDeletes();
                $table->timestamps();
                $table->index(['uid', 'brand_id', 'category_id']);
            });
            DB::statement("ALTER TABLE `product_bases` comment '商品基础信息表'");
        }
        // INSERT INTO `release_apis`.`product_bases` (`id`, `title`, `product_no`, `subtitle`, `tag_ids`, `uid`, `brand_id`, `category_id`, `cover_img`, `gallery_img`, `unit`, `price`, `stock`, `weight`, `pack`, `remark`, `status`, `deleted_at`, `created_at`, `updated_at`) VALUES ('85', '绿冰', 'G100000001', '绿豆', NULL, '2', '2', '38', '143', NULL, '千克', '5000000', '1', '10000000', NULL, NULL, 'normal', NULL, '2023-11-29 11:25:13', '2023-11-29 11:25:13');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('product_bases');
    }
}
